import request from '@/utils/request'


// 获取业务订单列表时，将订单状态为'3'（退款中）的优先级设为最高，排在最前面
export function listOrderSummary(query) {
  return request({
    url: '/ruoyi/order/selectOrderSummaryList',
    method: 'get',
    params: query
  })
}


// 查询订单信息列表
export function listOrder(query) {
  return request({
    url: '/ruoyi/order/list',
    method: 'get',
    params: query
  })
}

// 查询订单信息详细
export function getOrder(orderId) {
  return request({
    url: '/ruoyi/order/' + orderId,
    method: 'get'
  })
}

// 新增订单信息
export function addOrder(data) {
  return request({
    url: '/ruoyi/order',
    method: 'post',
    data: data
  })
}

// 修改订单信息
export function updateOrder(data) {
  return request({
    url: '/ruoyi/order',
    method: 'put',
    data: data
  })
}

// 删除订单信息
export function delOrder(orderId) {
  return request({
    url: '/ruoyi/order/' + orderId,
    method: 'delete'
  })
}



/**
 * 审核退款申请
 * @param {number|string} applicationId - 退款申请ID
 * @param {Object} auditData - 审核数据
 * @param {string} auditData.auditStatus - 审核状态 ("1"=通过, "2"=拒绝)
 * @param {string} [auditData.auditReason] - 审核原因（可选）
 * @returns {Promise}
 */
export function auditRefundApplication(refundId, auditData) {
  // 1. 参数验证
  const id = Number(refundId);
  if (isNaN(id)) {
    return Promise.reject(new Error('退款ID必须是数字'));
  }
  
  if (!auditData || !auditData.auditStatus) {
    return Promise.reject(new Error('审核状态是必填项'));
  }
  
  if (auditData.auditStatus !== '1' && auditData.auditStatus !== '2') {
    return Promise.reject(new Error('审核状态必须是"1"(通过)或"2"(拒绝)'));
  }
  
  // 2. 发送请求
  return request({
    url: `/ruoyi/order/auditRefundApplication/${id}`,
    method: 'put',
    data: auditData
  })
}